import java.net.*;
import java.io.*;

public class MulticastReceiver {
    public static void main(String[] args) throws IOException {
        // 创建一个多播接收器
        MulticastSocket socket = new MulticastSocket(12345);
        InetAddress group = InetAddress.getByName("224.0.0.1");
        socket.joinGroup(group);

        // 绑定到一个端口
        socket.bind(new InetSocketAddress(group, 12345));

        // 接收数据
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
        socket.receive(packet);

        // 处理接收到的数据
        String received = new String(packet.getData(), 0, packet.getLength());
        System.out.println("接收到： " + received);

        socket.leaveGroup(group);
        socket.close();
    }
}
